package bing.web.view.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Lists;

import bing.web.view.pojo.PageBean;
import bing.web.view.pojo.UserBean;

@Controller
@RequestMapping("/user")
public class UserController {

	@RequestMapping(value="/getUserList", produces ="application/json;charset=UTF-8",method=RequestMethod.POST)
	@ResponseBody
	public PageBean<UserBean> seach(HttpServletRequest request) {
		//pageNo
		int pageNo = Integer.parseInt(request.getParameter("pageNo"));
		
		PageBean<UserBean> userPage=new PageBean<UserBean>();
		List<UserBean> userList=Lists.newArrayList();
		
		int begin=(pageNo-1)*userPage.getPageSize();
		int end=begin+userPage.getPageSize();
		for(int i=begin;i<end;i++) {
			UserBean user=new UserBean();
			user.setId(String.valueOf(i));
			user.setName("user-"+i);
			userList.add(user);
		}
		userPage.setDataList(userList);
		userPage.setSumRows(5);
		
		System.out.println("search size:"+userList.size());
		return userPage;
	}
}
